package sort.comparison;

import java.util.Random;

/**
 * Created by Yasin H on 2017/7/30.
 */
public class Base {

    public static boolean less(Comparable v, Comparable w) {
        return v.compareTo(w) < 0;
    }

    public static void swap(Comparable[] a, int i, int j) {
        Comparable t = a[i];
        a[i] = a[j];
        a[j] = t;
    }

    public static void show(Comparable[] a) {
        for (Comparable anA : a)
            System.out.println(anA);
    }

    public static boolean isSort(Comparable[] a) {
        for (int i = 1; i < a.length; i++)
            if (less(a[i], a[i - 1]))
                return false;
        return true;
    }

    public static void shuffle(Comparable[] a) {
        Random random = new Random();
        for (int i = a.length; i > 1; i--)
            swap(a, i - 1, random.nextInt(i));
    }

}
